package edu.mse.camel.client.session.views;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class UsernamePasswordDialog extends Dialog {
	
	private String username;
	private String password;
	private Text usernameField;
	private Text passwordField;
	
	public UsernamePasswordDialog(Shell parentShell) {
		super(parentShell);
		setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX);
	}

	@Override
	protected void buttonPressed(int buttonId) {
		if(buttonId == 0){
			username = usernameField.getText();
			password = passwordField.getText();			
		}
		else
		{
			username = "";
			password = "";
		}
		
		super.buttonPressed(buttonId);
	}

	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		// TODO Auto-generated method stub
		super.createButtonsForButtonBar(parent);
	}

	@Override
	protected Control createDialogArea(Composite parent) {

		Composite comp = (Composite) super.createDialogArea(parent);
		comp.getShell().setText(DialogMessages.SessionDialog_Login);
		
		GridLayout layout = (GridLayout) comp.getLayout();
	    layout.numColumns = 2;

	    Label usernameLabel = new Label(comp, SWT.RIGHT);
	    usernameLabel.setText("Username: ");

	    usernameField = new Text(comp, SWT.SINGLE);
	    GridData data = new GridData(GridData.FILL_HORIZONTAL);
	    usernameField.setLayoutData(data);
	    
	    Label passwordLabel = new Label(comp, SWT.RIGHT);
	    passwordLabel.setText("Password: ");

	    passwordField = new Text(comp, SWT.SINGLE | SWT.PASSWORD);
	    data = new GridData(GridData.FILL_HORIZONTAL);
	    passwordField.setLayoutData(data);

	    return comp;
	}

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

}
